<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:st="http://java.sun.com/jsf/composite/store">

    <ui:define name="content">
        <h:form>
            <p:panel rendered="#{!storeTransferRequestController.printPreview}">
                <f:facet name="header" >                                  
                    <h:panelGrid columns="4" style="min-width: 100%;" >                        
                        <h:outputLabel value="To :#{storeTransferRequestController.bill.toDepartment.name} " />     
                        <p:commandButton  value="Request" action="#{storeTransferRequestController.request}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;">
                        </p:commandButton>
                        <p:commandButton  value="New Bill" action="#{storeTransferRequestController.recreate}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;">
                        </p:commandButton>                        

                    </h:panelGrid>
                </f:facet>
                <p:panelGrid columns="2">
                    <p:panelGrid columns="3">                        
                        <f:facet name="header">
                            Select Department To Request For
                        </f:facet>
                        <p:autoComplete converter="departmentConverter" value="#{storeTransferRequestController.bill.toDepartment}" 
                                        forceSelection="true"
                                        completeMethod="#{departmentController.completeDept}" var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" />                    
                    </p:panelGrid>
                    <p:panel header="Add Item ">
                        <p:autoComplete  value="#{storeTransferRequestController.currentBillItem.item}"
                                         forceSelection="true"
                                         completeMethod="#{itemController.completeStoreItem}" 
                                         var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >
                            <p:column headerText="Items" style="width: 10px!important;">
                                <h:outputLabel value="#{vt.name}"></h:outputLabel>
                            </p:column>
                            <p:column headerText="Code" style="width: 5px!important;" >
                                <h:outputLabel value="#{vt.code}"></h:outputLabel>
                            </p:column>
                            <f:ajax execute="@this" event="blur" render="#{p:component('tab')}" listener="#{storeTransferRequestController.onEdit()}"/>
                        </p:autoComplete>
                        <p:inputText autocomplete="off" value="#{storeTransferRequestController.currentBillItem.tmpQty}"/>
                        <p:commandButton value="Add Item" action="#{storeTransferRequestController.addItem}" ajax="false"/>
                    </p:panel>
                </p:panelGrid>
                <p:dataTable styleClass="noBorder" var="bi"  scrollable="true" 
                             scrollHeight="250"  value="#{storeTransferRequestController.billItems}"
                             sortOrder="#{bi.searialNo}" id="itemList" editable="true" >  

                    <f:facet name="header">  
                        Bill Item 
                    </f:facet>  

                    <p:column headerText="Item Name" >  
                        #{bi.item.name} 
                    </p:column>  

                    <p:column headerText="Qty" >                          
                        <p:inputText autocomplete="off"  id="qty" value="#{bi.tmpQty}" label="Qty">                         
                            <f:ajax event="blur" render=":#{p:component('tab')} "  execute="@this" listener="#{storeTransferRequestController.onEdit(bi)}" ></f:ajax>
                            <f:ajax event="focus" render=":#{p:component('tab')} "  execute="@this" listener="#{storeTransferRequestController.onEdit(bi)}" ></f:ajax>
                        </p:inputText>
                    </p:column>  

                    <p:column>
                        <p:commandButton ajax="false" value="Remove" action="#{storeTransferRequestController.remove(bi)}"/>
                    </p:column>
                </p:dataTable>  

                <p:spacer height="50"/>
                <st:history/>
 

            </p:panel>   
            <p:panel rendered="#{storeTransferRequestController.printPreview}" >
                <p:commandButton value="New Bill" ajax="false" action="#{storeTransferRequestController.recreate}" >
                </p:commandButton>
                <p:commandButton value="Reprint" ajax="false" >
                    <p:printer target="gpBillPreview" ></p:printer>
                </p:commandButton>
                <h:panelGroup id="gpBillPreview">
                    <st:transferRequest  bill="#{storeTransferRequestController.bill}" />    
                </h:panelGroup>
            </p:panel>

        </h:form>
    </ui:define>  

</ui:composition>
